#ifndef CBUSSCHEDULERINTERFACE_H
#define CBUSSCHEDULERINTERFACE_H

#include "interface/IInterface.h"
#include "cbusschedule.h"
#include "qtablewidget.h"
#include <QKeyEvent>

namespace Ui {
    class BusScheduler;
}

namespace interface
{
#define COLUMN_COUNT_FOR_BUS 4

class CBusSchedulerInterface : public IInterface
{
    Q_OBJECT

public:
    CBusSchedulerInterface(IInterface *parent = 0);
    ~CBusSchedulerInterface();

private Q_SLOTS:
    // button OK
    void Search();

    // button CANCEL
    void Cancel();

    // slots for table widget
    // when an item of the table has been clicked, this function will be invoked.
    void SelectTableItem( int row, int column );

    void myToggled(bool checked);

    void searchStart();
    void searchEnd();

    void showAllStart();
    void showAllEnd();
    void showAllStartAndEnd();

private:
    // prepare for the background setting
    virtual void UiSetting(Ui::BusScheduler *ui);

    // fill the table
    void FillTable(QTableWidget * pTableView, QList< vector<BUS_INFO_NAME_BASED> >& busInfo);

    // format the table
    void FormatTable(QTableWidget * pTableView);

    void FindAllQualifiedStations(QString abbr, QSet<QString>& stations, QStringList& result);

private:
    Ui::BusScheduler *m_pUi;

    int m_chosenBus; // it is the row number of the table cell

    QList< vector<BUS_INFO_NAME_BASED> > m_busGeneralInfo;

    //items for table view
    vector<vector<QTableWidgetItem*> > m_vecItem;

    BUS_SCHEDULER_ORDER m_order;

    QSet<QString> m_uniqueStationNames;

    // the index for start and end
    int m_chosenForStart;
    int m_chosenForEnd;

    // the input text
    QString m_inputTextStart;
    QString m_inputTextEnd;

    // enum for tale column order, which must aglin to the extract order in the table
    enum
    {
        BUS_NAME = 0,
        START_PLACE,
        END_PLACE,
        INTERVAL
    };

};
}

#endif // CBUSSCHEDULERINTERFACE_H
